#include <iostream>
#include <pthread.h>
#include <unistd.h>
#include "conc_queue.hpp"

using namespace std;

using namespace cv::gapi::own;

    pthread_t pth[10];
concurrent_bounded_queue<int> g_q;

void *popThdFunc(void *argc);
void *minitorThdFunc(void *argc)
{
    size_t count = 0;
    while (1) {
        sleep(5);
    
       g_q.get_number(count);
       cout << "current count:" << count << endl;
        if (count > 50)
            pthread_create(&pth[6], NULL, popThdFunc, NULL);
    }

}

void *pushThdFunc(void *argc)
{

    for (int i = 0; i < 100; i++) {
        sleep(1);

        g_q.push(i);

        cout << "push one!" << endl;
    }

}

void *popThdFunc(void *argc)
{
    for (int i = 0; i < 100; i++) {
        sleep(1);
        int x;
        g_q.pop(x);

        cout << "get one:" << x <<endl;
    }
}


int main(int argc, const char *argv[])
{
 

    pthread_create(&pth[0], NULL, minitorThdFunc, NULL);

    g_q.set_capacity(100);
    for (int i = 1; i < 4; i++) {
        pthread_create(&pth[i], NULL, pushThdFunc, NULL);
    }

    for (int i = 4; i < 6; i++) {
        pthread_create(&pth[i], NULL, popThdFunc, NULL);
    }

    getchar();

    return 0;
}
